package com.shg.web.interceptor;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.shg.web.tools.WebTool;


public class AdminInterceptor implements Interceptor {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		Object object = ActionContext.getContext().getSession().get(WebTool.SHG_MANAGER_ADMIN);
		
		//设置用户当前访问的界面,方便用户登录后直接跳转到前一个页面
		HttpServletRequest request=ServletActionContext.getRequest();
		String path=request.getRequestURI();
		//访问服务器所带有的参数信息
		String queryInfo=request.getQueryString();
		if(queryInfo!=null&&(!queryInfo.equals(""))){
			path=path+"?"+queryInfo;
		}
		System.out.println("用户访问的路径是:"+path);
		request.setAttribute("path", path);
		
		if(object!=null){
			return invocation.invoke();
		}
		return "login";
	}


}
